#!/bin/bash

# Generate vm public/private key pair into private keystore
echo Generating vm public private key pair
keytool -genkey -alias vmprivate -keystore vm.private -storetype JKS -keyalg rsa -dname "CN=Your Name, OU=Your Organizational Unit, O=Your Organization, L=Your City, S=Your State, C=Your Country" -storepass vmpass -keypass vmpass

# Generate em public/private key pair
echo Generating em public private key pair
keytool -genkey -alias emprivate -keystore em.private -storetype JKS -keyalg rsa -dname "CN=Your Name, OU=Your Organizational Unit, O=Your Organization, L=Your City, S=Your State, C=Your Country" -storepass empass -keypass empass

# Generate mf public/private key pair into private keystore
echo Generating mf public private key pair
keytool -genkey -alias mfprivate -keystore mf.private -storetype JKS -keyalg rsa -dname "CN=Your Name, OU=Your Organizational Unit, O=Your Organization, L=Your City, S=Your State, C=Your Country" -storepass mfpass -keypass mfpass

# Export vm public key and import it into public keystore
echo Generating vm public key file
keytool -export -alias vmprivate -keystore vm.private -file temp.key -storepass vmpass
keytool -import -noprompt -alias vmpublic -keystore vm.public -file temp.key -storepass public
rm -f temp.key

# Export em public key and import it into public keystore
echo Generating em public key file
keytool -export -alias emprivate -keystore em.private -file temp.key -storepass empass
keytool -import -noprompt -alias empublic -keystore em.public -file temp.key -storepass public
rm -f temp.key

# Export em public key and import it into public keystore
echo Generating mf public key file
keytool -export -alias mfprivate -keystore mf.private -file temp.key -storepass mfpass
keytool -import -noprompt -alias mfpublic -keystore mf.public -file temp.key -storepass public
rm -f temp.key
